Component({
  properties: {
    goods_id: String,
    is_favorite: Number,
    name: String,
    attr_group_list: Array,
    collection_count: String,
    pic_list: Array
  },

  data: {
    grade_select: false,
    checked: 0
  },
  attached() {
    setTimeout(() => {
      this.attrData(this.data.goods_id, this.data.attr_group_list[0].attr_list[0].attr_id)
      this.setData({
        checked: this.data.attr_group_list[0].attr_list[0].attr_id
      })
    }, 1000);
  },
  methods: {
    // 收藏点击
    clickcollect() {
      console.log()
      if (this.data.is_favorite == 0) {
        this.setData({
          is_favorite: 1
        })
      } else {
        this.setData({
          is_favorite: 0
        })
      }
      this.collectData(this.data.goods_id)
    },
    // 收藏数据提交
    collectData(e) {
      wx.showLoading({
        title: '加载中...',
      });
      var _this = this
      getApp().request({
        url: getApp().api.crowdfund.collection,
        method: "POST",
        data: {
          goods_id: e,
          status: _this.data.is_favorite
        },
        success(res) {
          wx.hideLoading();
          _this.triggerEvent('collect', _this.data.goods_id);
        },
        fail(res) {}
      })
    },
    // 支付框出现
    submitorder() {
      this.setData({
        grade_select: true
      })
    },
    // 支付框隐藏
    hintmask() {
      this.setData({
        grade_select: false
      })
    },
    // 阻止事件冒泡
    stopclick() {},
    // 挡位选择
    optionGears(e) {
      var id = e.currentTarget.dataset.id
      this.setData({
        checked: id
      })
      this.attrData(this.data.goods_id, id)
    },
    attrData(goods_id, attr_id) {
      wx.showLoading({
        title: '加载中...',
      });
      var _this = this
      getApp().request({
        url: getApp().api.crowdfund.attr_info,
        method: "GET",
        data: {
          goods_id: goods_id,
          attr_list: "[" + attr_id + "]",
          number: 1,
          type: "crowdfund"
        },
        success(res) {
          wx.hideLoading();
          console.log(res)
          _this.setData({
            price: res.data.price,
            pic: res.data.pic,
            num: res.data.num
          })
        },
        fail(res) {}
      })
    },
    orderskip() {
      var goods_info = '{"goods_id":"' + this.data.goods_id + '","attr":[{"attr_group_id":' + this.data.attr_group_list[0].attr_group_id + ',"attr_id":' + this.data.checked + '}],"num":1}'
      this.data.attr_group_list[0]
      wx.navigateTo({
        url: '/crowdfund/order-submit/order-submit?goods_info=' + goods_info
      })
    }
  }
})